package com.zy.common.utils.ip;


import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@Component
public class IpAddressLog {

    private static String getIpAddress() {
        try {
            return InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            log.error("", e);
            return null;
        }
    }

    public static void log(Environment env) {
        log.info("\n----------------------------------------------------------\n\t" +
                        "com.zy.auth Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\thttp://127.0.0.1:{}\n\t" +
                        "External: \thttp://{}:{}\n" +
                        "----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                env.getProperty("server.port"),
                getIpAddress(),
                env.getProperty("server.port"));


        System.out.println("\n ________           ___    ___      ________           ________     \n" +
                "|\\_____  \\         |\\  \\  /  /|    |\\   ___  \\        |\\   __  \\    \n" +
                " \\|___/  /|        \\ \\  \\/  / /    \\ \\  \\\\ \\  \\       \\ \\  \\|\\ /_   \n" +
                "     /  / /         \\ \\    / /      \\ \\  \\\\ \\  \\       \\ \\   __  \\  \n" +
                "    /  /_/__         \\/  /  /        \\ \\  \\\\ \\  \\       \\ \\  \\|\\  \\ \n" +
                "   |\\________\\     __/  / /           \\ \\__\\\\ \\__\\       \\ \\_______\\\n" +
                "    \\|_______|    |\\___/ /             \\|__| \\|__|        \\|_______|\n" +
                "                  \\|___|/                                           \n" +
                "                                                                    \n" +
                "                                                                   ");

    }
}
